#include "ros/ros.h"
#include "tf2_ros/static_transform_broadcaster.h"
#include "tf2/LinearMath/Quaternion.h"

int main(int argc, char **argv)
{
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "static_pub");
    ros::NodeHandle nh;
    // 创建发布对象
    tf2_ros::StaticTransformBroadcaster pub;
    // 组织被发布消息
    geometry_msgs::TransformStamped tfs;
    tfs.header.stamp = ros::Time::now();
    tfs.header.frame_id = "base_link"; //相对坐标系当中被参考的那个
    tfs.child_frame_id = "laser";
    tfs.transform.translation.x = 0.2;
    tfs.transform.translation.y = 0.0;
    tfs.transform.translation.z = 0.5;

    tf2::Quaternion q; //创建四元素对象
    // 向该对象设置欧拉角，可以将欧拉角转为四元素
    q.setRPY(0, 0, 0); //单位是弧度
    tfs.transform.rotation.x = q.x();
    tfs.transform.rotation.y = q.y();
    tfs.transform.rotation.z = q.z();
    tfs.transform.rotation.w = q.w();

    // 发布数据
    pub.sendTransform(tfs);
    ros::spin();

    // 需要参考欧拉角转换
    return 0;
}